//
//  CapitalFlowController.m
//  YiBaoStore
//
//  Created by 吕清毅 on 2018/10/6.
//  Copyright © 2018年 小河. All rights reserved.
//

#import "CapitalFlowController.h"
#import "CapitaFlowTableViewCell.h"
#import "RechargeTableViewCell.h"
#import "BillDetailViewController.h"

@interface CapitalFlowController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *dataArray;
@property (nonatomic, strong) UIView *headView;
@end

@implementation CapitalFlowController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setNavi];
//    [self getData];
    [self setUpTable];
}

- (void)setUpTable
{
    if (self.tableView == nil) {
        if (@available(iOS 11.0, *)) {
            self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0,self.headView.bottom, SCREENWIDTH, SCREENHEIGHT-self.headView.height-BottomHeight_xs) style:UITableViewStylePlain];
        } else {
            // Fallback on earlier versions
            self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0,self.headView.bottom, SCREENWIDTH, SCREENHEIGHT-self.headView.height-BottomHeight) style:UITableViewStylePlain];
        }
        self.tableView.backgroundColor = TotalWhite;
        self.tableView.delegate = self;
        self.tableView.dataSource = self;
        self.tableView.estimatedRowHeight = 0;
        self.tableView.estimatedSectionHeaderHeight = 0;
        self.tableView.estimatedSectionFooterHeight = 0;
        [self.tableView registerClass:[CapitaFlowTableViewCell class] forCellReuseIdentifier:@"CapitaFlowTableViewCell"];
        [self.tableView registerClass:[RechargeTableViewCell class] forCellReuseIdentifier:@"RechargeTableViewCell"];
        self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        self.tableView.tableFooterView = [UIView new];
        [TTKUtil setAutomaticallyAdjustsScrollViewInsetsWidth:self.tableView withView:self];
        //self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(getNewData)];
        [self.view addSubview:self.tableView];
    }
}

#pragma mark -- table Delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 6;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        RechargeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RechargeTableViewCell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    else
    {
        CapitaFlowTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CapitaFlowTableViewCell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    return [UITableViewCell new];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        BillDetailViewController *billVC = [BillDetailViewController new];
        [self.navigationController pushViewController:billVC animated:YES];
    }else
    {
        NSLog(@"222");
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        return 71;
    }
    return 86;
}

- (void)setNavi
{
    self.bgNavView.hidden = YES;
    self.headView = [UIView new];
    if (@available(iOS 11.0, *)) {
        self.headView.frame = CGRectMake(0, 0, SCREENWIDTH, TopBarHeight_xs+78+48);
    } else {
        // Fallback on earlier versions
        self.headView.frame = CGRectMake(0, 0, SCREENWIDTH, TopBarHeight+78+48);
    }
    self.headView.backgroundColor = goldColor;
    [self.view addSubview:self.headView];
    
    UIView *navi = [UIView new];
    if (@available(iOS 11.0, *)) {
        navi.frame = CGRectMake(0, 0, SCREENWIDTH, TopBarHeight_xs);
    } else {
        // Fallback on earlier versions
        navi.frame = CGRectMake(0, 0, SCREENWIDTH, TopBarHeight);
    }
    navi.backgroundColor = ClearColor;
    [self.headView addSubview:navi];
    
    UIImageView *leftIV = [UIImageView new];
    leftIV.frame = CGRectMake(15, navi.height-15-18, 18, 14);
    leftIV.image = [UIImage imageNamed:@"back"];
    [navi addSubview:leftIV];
    
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(8, navi.height-40, 32, 28);
    leftBtn.backgroundColor = ClearColor;
    [leftBtn addTarget:self action:@selector(leftBtnBackClick:) forControlEvents:UIControlEventTouchUpInside];
    [navi addSubview:leftBtn];
    
    UILabel *titleLab = [UILabel new];
    CGFloat left = 30+18;
    titleLab.frame = CGRectMake(left, navi.height-13-18, SCREENWIDTH-96, 18);
    titleLab.textColor = UIColorFromHex(0x020200);
    titleLab.font = FontWithSize(18);
    titleLab.attributedText = [TTKUtil getAtttributeStringWithLineSpace:0 kern:1.5 and:@"资金流水"];
    titleLab.textAlignment = NSTextAlignmentCenter;
    [navi addSubview:titleLab];
    
    NSArray *titleArray = @[@"充值",@"贷款",@"扣除收益"];
    NSArray *desArray = @[@"+2000",@"-1200",@"-300"];
    for (int i = 0; i < 3; i++) {
        UILabel *label = [UILabel new];
        label.frame = CGRectMake(SCREENWIDTH/3*i, navi.bottom+14, SCREENWIDTH/3, 14);
        label.textColor = UIColorFromHex(0x020200);
        label.font = FontWithSize(14);
        label.attributedText = [TTKUtil getAtttributeStringWithLineSpace:0 kern:1.17 and:titleArray[i]];
        label.textAlignment = NSTextAlignmentCenter;
        [self.headView addSubview:label];
        
        UILabel *desLab = [UILabel new];
        desLab.frame = CGRectMake(SCREENWIDTH/3*i, label.bottom+12, SCREENWIDTH/3, 18);
        desLab.textColor = UIColorFromHex(0x020200);
        desLab.font = FontSemiboldSize(18);
        desLab.tag = 50+i;
        desLab.attributedText = [TTKUtil getAtttributeStringWithLineSpace:0 kern:1.5 and:desArray[i]];
        desLab.textAlignment = NSTextAlignmentCenter;
        [self.headView addSubview:desLab];
    }
    
    UIView *bottomView = [UIView new];
    bottomView.frame = CGRectMake(0, self.headView.height-48, SCREENWIDTH, 48);
    bottomView.backgroundColor = UIColorFromHex(0xF9F9F9);
    [self.headView addSubview:bottomView];
    
    UIImageView *calenIV = [UIImageView new];
    calenIV.frame = CGRectMake(SCREENWIDTH-31, 16, 16, 16);
    calenIV.image = [UIImage imageNamed:@"calen"];
    [bottomView addSubview:calenIV];
    
    UIButton *calBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    calBtn.frame = CGRectMake(calenIV.left-8, calenIV.top-8, 32, 32);
    calBtn.backgroundColor = ClearColor;
    [calBtn addTarget:self action:@selector(changeCalen:) forControlEvents:UIControlEventTouchUpInside];
    [bottomView addSubview:calBtn];
    
    UILabel *calLab = [UILabel new];
    calLab.frame = CGRectMake(15, 17, SCREENWIDTH-56, 14);
    calLab.textColor = UIColorFromHex(0x020200);
    calLab.font = FontWithSize(14);
    calLab.attributedText = [TTKUtil getAtttributeStringWithLineSpace:0 kern:1.17 and:@"2018-08-07至2018-09-20"];
    [bottomView addSubview:calLab];
}

#pragma mark -- 修改日历
- (void)changeCalen:(UIButton *)btn
{
    NSLog(@"11");
}

- (void)leftBtnBackClick:(UIButton *)btn
{
    [self.navigationController popViewControllerAnimated:YES];
}

@end
